import {
  _decorator,
  Component,
  EventKeyboard,
  Input,
  KeyCode,
  input,
} from "cc";

import { AnimEvents3 } from "../Animation3/AnimEvents3";
import { WarroirStates } from "../../Test1/Enums/EnumPool";
const { ccclass, property } = _decorator;

@ccclass("InputKey3")
export class InputKey3 extends Component {
  onKeyDown(event: EventKeyboard) {
    switch (event.keyCode) {
      case KeyCode.ENTER:
        console.log("Press key", event.keyCode);
        const animComp = this.getComponent(AnimEvents3);
        animComp.stateTransition(WarroirStates.WARRIOR_ATTACK);
        break;
    }
  }

  onKeyUp(event: EventKeyboard) {
    switch (event.keyCode) {
      case KeyCode.ENTER:
        // console.log("Release key", event.keyCode);
        break;
    }
  }

  registerMethod(target?: any) {
    console.log("registerMethod.target", target);
    input.on(Input.EventType.KEY_DOWN, this.onKeyDown, target);
    input.on(Input.EventType.KEY_UP, this.onKeyUp, target);
  }

  exitEventMethod(target?: any) {
    input.off(Input.EventType.KEY_DOWN, this.onKeyDown, target);
    input.off(Input.EventType.KEY_UP, this.onKeyUp, target);
  }
}
